package com.example.drug.utils;

import com.example.drug.jpa.PharmacistRepository;
import com.example.common.entity.Pharmacist;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Slf4j
@Component
public class UserUtils {

    @Resource
    private HttpServletRequest request;
    @Resource
    private PharmacistRepository pharmacistRequest;
     

    /**
     * 获取当前登录用户信息
     *
     * @return 用户信息
     */
    public Pharmacist getUser() {
        String id = request.getHeader("UID");
        Long dcId = Long.valueOf(id).longValue();
        Pharmacist baseInfo =  pharmacistRequest.findById(dcId).orElse(null);
        return baseInfo;
    }

    public long getUserID() {
        String id = request.getHeader("UID");
        return Long.valueOf(id).longValue();
    }
}
